using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace XEntity.InventoryItemSystem
{
    //This script is attached to the UI representation of the item container. An example item container UI prefab is provided with the asset.
    public class ItemContainerWithFastBar : ItemContainer
    {

        protected override void Awake()
        {
            base.Awake();
        }

        protected override void CreateSlotOptionsMenu(SlotOptions[] config, Interactor interactor)
        {
            base.CreateSlotOptionsMenu(config, interactor);
        }

        protected override void Update()
        {
            base.Update();
        }

        //All the container variables are assigned here based.
        protected override void InitializeContainer(){
            base.InitializeContainer();
            InitializeFastBar();
        }

        protected Transform fastBarUI;
        private void InitializeFastBar(){
            fastBarUI = this.containerPanel.Find("FastBar");

            Transform slotHolder = fastBarUI.Find("Slot Holder");
            ItemSlot[] newslots = new ItemSlot[slotHolder.childCount];

            for (int i = 0; i < newslots.Length; i++)
            {
                ItemSlot slot = slotHolder.GetChild(i).GetComponent<ItemSlot>();
                newslots[i] = slot;
                Button slotButton = slot.GetComponent<Button>();
                slotButton.onClick.RemoveAllListeners();
                slotButton.onClick.AddListener(delegate { OnSlotClicked(slot, containerInteractor); });
            }
            
            int totalSlots = slots.Length + newslots.Length;
            ItemSlot[] mergedSlots = new ItemSlot[totalSlots];
            Array.Copy(slots, 0, mergedSlots, 0, slots.Length);
            Array.Copy(newslots, 0, mergedSlots, slots.Length, newslots.Length);
            slots = mergedSlots;

        }
    }
}
